Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some code under FEATURE_STUBS_AS_IL #104731

Merged
merged 33 commits into from
Sep 19, 2024
Merged

Conversation

huoyaoyuan
Copy link
Member

@huoyaoyuan huoyaoyuan commented Jul 11, 2024

There's no actually no IL stubs under this feature switch now, only asm stubs.

This PR addresses the simple cases. On all platforms except Windows x86, single cast delegate is written in invariant assembly code.

Remaining code under the feature switch is COM call stub, which is more complicated and is better separated out.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 11, 2024
@jkotas jkotas changed the title Cleanup some code under FEATURE_STUBS_AS_AL Cleanup some code under FEATURE_STUBS_AS_IL Jul 12, 2024
src/coreclr/vm/stubmgr.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/stubmgr.cpp Outdated Show resolved Hide resolved
@jkotas
Copy link
Member

jkotas commented Jul 17, 2024

Code quality

If this helps with code quality, could you please make the same change in

codeStream.EmitLdArg(0);
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(functionPointerField.InstantiateAsOpen()));
as well? It is naot equivalent of this stub.

@huoyaoyuan
Copy link
Member Author

The same tests in DI are still failing. Can it be related to the signature instantiation in ILC?

if (method.OwningType.HasInstantiation)
{
// If the owning type is generic, the signature will contain T's and U's.
// We need !0's and !1's.
TypeDesc[] typesToReplace = new TypeDesc[method.OwningType.Instantiation.Length];
TypeDesc[] replacementTypes = new TypeDesc[typesToReplace.Length];
for (int i = 0; i < typesToReplace.Length; i++)
{
typesToReplace[i] = method.OwningType.Instantiation[i];
replacementTypes[i] = context.GetSignatureVariable(i, method: false);
}
TypeDesc[] parameters = new TypeDesc[method.Signature.Length];
for (int i = 0; i < parameters.Length; i++)
{
parameters[i] = method.Signature[i].ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes);
}
TypeDesc returnType = method.Signature.ReturnType.ReplaceTypesInConstructionOfType(typesToReplace, replacementTypes);
signature = new MethodSignature(signature.Flags, signature.GenericParameterCount, returnType, parameters);
}
Is it also required for coreclr?

@jkotas
Copy link
Member

jkotas commented Jul 18, 2024

The same tests in DI are still failing. Can it be related to the signature instantiation in ILC?

We should not need a special signature instantiation like that in CoreCLR. I suspect that it is related to a special delegate calling convention used for delegate Invocation in some cases. The delegate target cannot be called via pointer - it must be called as Delegate.Invoke method so that the special calling convention kicks in.

Do you know if the Invoke method is used in the DI on a performance critical path?

This is proving to be much harder than what I thought it is going to be.

@huoyaoyuan
Copy link
Member Author

I can't see more open issues for this, and main should be open for 10.0 now.

Given the stub is not in hot path, it's should be a viable solution to call a trace helper like the multi-cast stub.

@mangod9
Copy link
Member

mangod9 commented Sep 16, 2024

@jkotas @noahfalk could you please take another look so we can merge?

@noahfalk
Copy link
Member

@jkotas @noahfalk could you please take another look so we can merge?

My only involvement so far was answering a question about singlecast delegate stepping for the debugger which was resolved out-of-scope for now. If you need me to I could spend time and dig into this much deeper but I am assuming that @jkotas already has the context so its more efficient for him to continue. Just let me know.

src/coreclr/debug/ee/frameinfo.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/amd64/cgencpu.h Outdated Show resolved Hide resolved
src/coreclr/vm/class.h Outdated Show resolved Hide resolved
src/coreclr/vm/comdelegate.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/comdelegate.cpp Show resolved Hide resolved
src/coreclr/vm/stubmgr.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/dllimport.h Outdated Show resolved Hide resolved
src/coreclr/vm/dllimport.h Outdated Show resolved Hide resolved
src/coreclr/vm/stublink.h Outdated Show resolved Hide resolved
src/coreclr/vm/stublink.h Outdated Show resolved Hide resolved
src/coreclr/vm/method.hpp Outdated Show resolved Hide resolved
@jkotas
Copy link
Member

jkotas commented Sep 19, 2024

I have pushed a commit with a small change to handle the new IL stub in stub manager. The manual debugger test from #104731 (comment) works fine now.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@jkotas
Copy link
Member

jkotas commented Sep 19, 2024

Remaining code under the feature switch is COM call stub, which is more complicated and is better separated out.

Do you plan to work on cleaning up the remaining code under the feature switch?

@huoyaoyuan huoyaoyuan deleted the stubs-as-il branch September 19, 2024 16:18
@huoyaoyuan
Copy link
Member Author

Do you plan to work on cleaning up the remaining code under the feature switch?

Aaron suggested me to avoid converting COM interop related code because the effort needed for reviewing. I'm already busy now until October.

If you can confirm the review effort on behalf of interop team, I can start to investigate this when I finish urgent tasks.

@jkotas
Copy link
Member

jkotas commented Sep 20, 2024

I gave it a shot in #108048.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants